package com.frank.demo.thread;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by Administrator on 2017/2/20.
 */
public class NumThread {

    public static void main(String[] args) throws InterruptedException {
        AtomicInteger count = new AtomicInteger(0);
        Executor executorPool = Executors.newFixedThreadPool(2);

        CountAdd countAdd1 = new CountAdd(count);
        CountAdd countAdd2 = new CountAdd(count);

        executorPool.execute(countAdd1);
        executorPool.execute(countAdd2);

        TimeUnit.SECONDS.sleep(2);
        System.out.println(count);
    }

}


class CountAdd implements Runnable{

    private AtomicInteger count;

    public CountAdd(AtomicInteger count) {
        this.count = count;
    }

    public void run() {
        for (int i = 0 ; i<500; i++)
            count.addAndGet(1);
        }

}
